Skip to contents

This function wraps numerous Leaflet features into a single, well-parametrized interface.

Usage

robomap(
  d,
  area,
  title = NULL,
  subtitle = "",
  caption = NULL,
  hovertext = list(flag = "", unit = ""),
  map_opacity = 0.9,
  tile_opacity = 0.7,
  map_palette = NULL,
  border_width = getOption("roboplot.trace.border")$width,
  legend = set_legend(),
  data_contour = FALSE,
  markers = FALSE,
  log_colors = NULL,
  rounding = 1,
  zoom = TRUE,
  ...
)

Arguments

d

Data frame. Data to be created a map from.

area

Symbol or string. Variable from argument 'd' to use to identify the areas described by the map. This must be of class sfc_MULTIPOLYGON.

title, subtitle

Characters. Labels for plot elements.

caption

Function or character. Use a string, or set_caption().

hovertext

List. Use a list with named characters flag and unit.

map_opacity, tile_opacity

Numeric. Values from 0 to 1, defining how opaque the map polygon fill color or underlying map tiles are. 0 removes the tile layer, but retains the polygon borders if any.

map_palette

Character or function. Must be a hexadecimal colors or valid css colors, or use set_heatmap() if specifying color breakpoints.

border_width

Integer. The width of polygon borders.

legend

Function. Use set_legend().

data_contour

Logical. Experimental. If TRUE, robomap() will produce a contour-like representation of the data, which does not conform to the boundaries of the polygons. This provides a smoother transition and helps in visualizing general trends across regions. Default is FALSE.

markers

Logical. Experimental. Whether markers will be added on the map based on the columns "lat" and "lon". Default is FALSE.

log_colors

Logical. Whether the colors scales is log or not.

rounding

Numeric. How robomap() rounds numeric values.

zoom

Logical. Whether the map is zoomable or not.

...

Placeholder for other parameters.

Value

A list of classes leaflet, htmlwidget and roboplot.robomap

Examples

# You can use `robomap()` to create interactive maps. Note that very large
# number of map polygons makes for slow rendering maps.
vaesto_postinumeroittain |>
  dplyr::filter(Alue == "Espoo") |>
  robomap(Postinumeroalue, title = "V\u00e4est\u00f6 Espoossa", caption = "Tilastokeskus")
# Default polygon colors are picked from trace colors set with # `set_roboplot_options()` based on luminosity. Control polygon colors with # `map_palette`. `robomap()` expands upon this as necessary. vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", subtitle = "Otanta", caption = "Tilastokeskus", map_palette = c("lightgreen", "darkred") )
# You might want to disallow zooming for some reason. The map will be draggable, # but zoom by buttons or scrolling is disabled. vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", subtitle = "Otanta", caption = "Tilastokeskus", zoom = FALSE )
# When necessary `robomap()` automatically logarithmically scales values to # add map readability. Control this with log_colors vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", caption = "Tilastokeskus", map_palette = c("lightgreen", "darkred"), log_colors = FALSE )
# Other controls you might need. vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", caption = "Tilastokeskus", map_palette = c("lightgreen", "darkred"), border_width = 2, tile_opacity = 0.2, map_opacity = 0.5 )
# Control the story you want to tell by using `set_heatmap()` with `map_palette`, # setting the colors and breakpoints. Use `legend` with `set_legend(breaks)` # to control how many entries the legend is split to. vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", caption = "Tilastokeskus", map_palette = set_heatmap(midvalue = 6000, midcolor = "yellow", maxcolor = "red"), legend = set_legend(breaks = 3), map_opacity = 1, border_width = 0 )
# Or just give the legend breaks vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", caption = "Tilastokeskus", # map_palette = set_heatmap(midvalue = 6000, midcolor = "yellow", maxcolor = "red"), legend = set_legend(breaks = c(3001, 6001, 9001)), map_opacity = 1, border_width = 0 )